/**
 * 
 */
package ui.model;

import java.text.NumberFormat;
import java.util.*;

import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;

import exceptions.*;

import model.Syllabus;
import appControll.AppController;

/**
 * @author Anthares & Hennek
 *
 */
public class SyllabusPrixTableModel extends AbstractTableModel {
	private ArrayList<Syllabus> content = new ArrayList<Syllabus>();
	private ArrayList<String> columnNames = new ArrayList<String>();
	private String[] tabPrix;
	private AppController app = new AppController();
	/**
	 * @throws DatabaseErrorException 
	 * @throws PasIdentificationException 
	 * @throws InvalidDataException 
	 * 
	 */
	public SyllabusPrixTableModel(ArrayList<Syllabus> cont) throws PasIdentificationException, DatabaseErrorException, InvalidDataException {
		columnNames.add("Intitulle");
		columnNames.add("Prix unitaire");
		content = cont;
		NumberFormat nf = NumberFormat.getCurrencyInstance();
		tabPrix = new String[content.size()];
		for(int i=0;i<content.size();i++){
			tabPrix[i]=nf.format(app.getPrixSyllabus(content.get(i)));
		}
	}

	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	@Override
	public int getColumnCount() {
		return columnNames.size();
	}
	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getRowCount()
	 */
	@Override
	public int getRowCount() {
		return content.size();
	}
	@Override
	public String getColumnName(int col){
		return columnNames.get(col);
	}
	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
	 */
	@Override
	public Object getValueAt(int row, int col) {
		Syllabus s = content.get(row);
		switch (col) {
		case 0: return s.getIntitule();
		case 1: return tabPrix[row];
		default:return null;
		}
	}
	public Class getColumnClass(int col){
		return String.class;
	}

}
